
    
<script setup >
    import request from '@/utils/request'

    import {APPID180 as  APPID,API_SECRET180 as API_SECRET, API_KEY180 as API_KEY } from '@/utils/APIKEY'
    import CryptoJS from "crypto-js";
/**
   * 获取websocket url
   * 该接口需要后端提供，这里为了方便前端处理
   */
   function getWebUrl() {
    // 请求地址根据语种不同变化
    var url = 'https://upload-ost-api.xfyun.cn/file/upload'
    var host = 'upload-ost-api.xfyun.cn'
    var apiKey = API_KEY
    var apiSecret = API_SECRET
    var date = new Date().toGMTString()
    var algorithm = 'hmac-sha256'
    var headers = 'host date request-line'
    var signatureOrigin = `host: ${host}\ndate: ${date}\nGET /v2/open-ise HTTP/1.1`
    var signatureSha = CryptoJS.HmacSHA256(signatureOrigin, apiSecret)
    var signature = CryptoJS.enc.Base64.stringify(signatureSha)
    var authorizationOrigin = `api_key="${apiKey}", algorithm="${algorithm}", headers="${headers}", signature="${signature}"`
    var authorization = btoa(authorizationOrigin)
    url = `${url}?authorization=${authorization}&date=${date}&host=${host}`
    return url
  }

  function toBase64(buffer) {
    var binary = ''
    var bytes = new Uint8Array(buffer)
    var len = bytes.byteLength
    for (var i = 0; i < len; i++) {
      binary += String.fromCharCode(bytes[i])
    }
    return window.btoa(binary)
  }




    const submit = (e) => {
        console.log(e.target.files[0])

        request({
            url:getWebUrl(),
            method: 'POST',
            data:{
                app_id: APPID,
                data: e.target.files[0],
                request_id: '20211213152023'
            }
        })
    }
</script>
<template>
        <input type="file"  @change="submit">
</template>
<style>
    
</style>